/*
* @Author: zlx
* @Date:   2018-02-27 10:08:24
* @Last Modified by:   zlx
* @Last Modified time: 2018-02-27 11:21:03
*/
$("#phone").val("");
$("#yzm").val("");
$("#newPassword").val("");
var zhengZ = /^1[34578]\d{9}$/;
var time=60;
//发送验证码
$(document).on('click','.send',function(){
	//获取验证码
	if($(this).attr('id')){
		type=$(this).attr('type');
		if(!zhengZ.test($('.phone_n').val())){
			tips('请输入正确的手机号');
			return false;
		}else if(!$('.phone_n').val()){
			tips('请先填写手机号');
			return false;
		}else{
			$.post(apicom+'mobile/view/member/sendSms',{
				phone:$('.phone_n').val(),
				type:2//忘记密码
			},function(res){
				if(typeof res == "string"){
		            res=JSON.parse(res);
		        }
				setTimeout(function(){
					tips(res.msg)
				},1000);
				$('.send').attr('id','');
                $('.send').text("重新获取" + "(" + (time) + ")");
                var setId = setInterval(function() {
                    if (time <= 0) {
                        $('.send').attr('id','send');
                        $('.send').text("发送验证码");
                        clearInterval(setId);
                        time=60;
                    } else {
                        time--;
                        $('.send').text("重新获取" + "(" + (time) + ")");
                    }
                }, 1000);
			})
		}
	}
})

//确认修改
$(document).on('click','.login a',function(){
    var phone=$("#phone").val();
    var yzm=$("#yzm").val();
    var password=$("#newPassword").val();
    var $this=$(this);
    if($(this).hasClass('fb')){
    	if(''==phone){
    		tips('请先填写手机号');
    		return false;
    	}
        if(!zhengZ.test(phone)) {
            tips("手机号码格式不正确");
            return false;
        }
        if (yzm.length == 0) {
            tips("验证码错误,请输入正确验证码");
            return false;
        }
        if (password.length == 0 || password.length < 6 || 20 < password.length || password == "") {
            tips("请输入6-20位密码");
            return false;
        }
        if (/\s/.test(password) || !(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/.test(password)) ) {
            tips("密码格式不正确");
            return false;
        }
        $.ajax({
            url:apicom+"mobile/view/member/forgetPassword",
            type:"post",
            data:{
                phone:phone,
                smsCode:yzm,
                rePassword:password
            },
            success:function(res){
            	if(typeof res == "string"){
		            res=JSON.parse(res);
		        }
                tips(res.msg)
                if(res.code==1){
                        $("#phone").val("");
                        $("#yzm").val("");
                        $("#newPassword").val("");
                        $(this).removeClass("fb");
                    setTimeout(function() {
                        $this.addClass('fb');
                        location.href = prepage;
                    }, 3000);
                }
            },
            error:function(err){
                tips("服务器错误！")
                setTimeout(function() {
                    $this.addClass('fb');
                }, 3000);
            }
        });
    }

});